home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / 80x0393.zip / H2NAME.ASM < prev    next >
Assembly Source File  |  1992-09-30  |  6KB  |  144 lines

  1. ;
  2. ;  H2NAME.ASM
  3. ;  LIBRARY routine which you may either store in a    
  4. ;  library, or simply compile it to an OBJ, and state:
  5. ;  (in any way if you want to use it...)              
  6. ;
  7. ;          EXTRN   HandleToName: Far
  8. ;
  9. ;  Author: Inbar Raz
  10. ;  Placed in public domain
  11. ;
  12.  
  13. Handle2Name     Segment
  14.  
  15.                 assume cs:Handle2Name
  16.  
  17.                 public HandleToName
  18.  
  19. EntrySize  EQU 0004h                    ; Length of table entry
  20. EntryCount EQU 0004h                    ; Number of table entries
  21.  
  22. ;███████████████████████████████████████████████████████████████████████████
  23. ;
  24. ; FAR PROC HandleToName
  25. ;
  26. ; PURPOSE:  Given a handle, return pointer to ASCIIZ file name
  27. ;
  28. ; INPUTS:   BX = Handle of file to be named
  29. ;
  30. ; OUTPUTS:  ES:DX => ASCIIZ file name (exactly 11 bytes long) (FCB format)
  31.  
  32. HandleToName    proc    far
  33.  
  34.         push    ax                      ; Save all used registers on stack
  35.         push    cx
  36.         push    dx
  37.         push    si
  38.         push    bp                      ; Will be used as the indes to the
  39.                                         ; SFTLength and SFTName fields
  40.  
  41.         push    bx                      ; Save handle
  42.  
  43.         mov     ah,030h                 ; Get DOS version
  44.         int     21h
  45.         xchg    al,ah                   ; Now adjust things for our compares
  46.         mov     cx,EntryCount           ; Four entries in table
  47.         call    @@GetOff                ; Figure out our offset
  48.  
  49. CODESTART EQU   $
  50.  
  51. @@GetOff:
  52.         pop     bx                      ; Calculate offsets. Since this is
  53.                                         ; a FAR Library routine, offsets
  54.                                         ; are never as reported by the
  55.                                         ; assembler at compilation time.
  56.         mov     bp,bx                   ; Calculate SFT offsets
  57.         dec     bp                      ;
  58.         dec     bp                      ; BP now points to SFTLength
  59.         add     bx,CODELEN              ; Calculate table's offset
  60.  
  61. @@looky:
  62.         cmp     ax,word ptr cs:[bx]     ; Is DOS version/rev correct?
  63.         ja      @@got_values            ; If it's greater, it's OK
  64.         add     bx,EntrySize            ; If not, check next entry
  65.         loop    @@looky                 ; And jump back up
  66.  
  67. ; should err_exit if < DOS 2.0 here, but...
  68.  
  69. @@got_values:
  70.         mov     ax,word ptr cs:[bx+00002h] ; Get SFTsize and NameOffs
  71.         mov     word ptr cs:[bp],ax     ; Store them the same way (cheat!)
  72.                                         ; Since we need to access both in the
  73.                                         ; same time, this will be the only time
  74.                                         ; we actually use BP and not the EQU's
  75.  
  76.         pop     bx
  77.  
  78.         mov     si,bx                   ; Save original file handle in SI
  79.         mov     ah,062h                 ; Get program's PSP
  80.         int     21h
  81.         mov     es,bx
  82.         les     bx,dword ptr es:[00034h] ; Point ES:BX to the PSP's JFT
  83.         mov     al,byte ptr es:[bx+si]  ; Now read table entry (index into SFT)
  84.         cbw                             ; Clear AH
  85.         mov     si,ax                   ; Rememer the SFT index
  86.         mov     ah,052h                 ; Get list of lists into ES:BX
  87.         int     21h
  88.         les     bx,dword ptr es:[bx+00004h] ; Point ES:BX to the SFT
  89.  
  90. @@NextSFT:                              ; ES:BX => SFT at this point
  91.         cmp     si,word ptr es:[bx+00004h] ; Is this handle in this SFT?
  92.         jb      @@SFT_ok                ; If so, we're in the correct table
  93.         sub     si,word ptr es:[bx+00004h] ; If not, adjust index for next table
  94.         les     bx,dword ptr es:[bx]    ; And load address of next SFT
  95.         jmp     @@nextSFT               ; Loop back again
  96.  
  97. @@SFT_ok:
  98.         mov     ax,si                   ; Recall our adjusted SFT index
  99.         mov     dl,SFTlength            ; SFTlength is the length of an SFT entry
  100.         mul     dl                      ; AX = (SFT index) * (SFT length)
  101.         mov     dl,SFTname              ; SFTname = offset from start of SFT
  102.         xor     dh,dh                   ; Clear out high half of DX
  103.         add     ax,dx                   ; AX = SFTindex * SFTlength + SFTname
  104.         add     bx,ax                   ; BX = Original offset + calc offset
  105.         mov     di,bx                   ; Now ES:DX => File name string
  106.  
  107.         pop     bp
  108.         pop     si
  109.         pop     dx
  110.         pop     cx
  111.         pop     ax                      ; Restore all trgisters from stack
  112.  
  113. Quit:
  114.         retf
  115.  
  116. SFTlength       EQU     byte ptr cs:[bp]
  117. SFTname         EQU     byte ptr cs:[bp+00001h]
  118.  
  119. ;SftLength
  120.         db      ?
  121. ;SftName
  122.         db      ?
  123.  
  124. CODELEN   EQU   $-CODESTART
  125.  
  126. ; Format of data table:
  127. ;
  128. ; DosMin   DB  0                        ; Minor DOS version
  129. ; DosMaj   DB  0                        ; Major DOS version
  130. ; SFTsize  DB  ?                        ; System File Table entry size
  131. ; NameOffs DB  ?                        ; Offset from SFT start to first name
  132.  
  133. Voodoo  db    000h,004h,03Bh,026h       ; Dos version 4.0
  134.         db    001h,003h,035h,026h       ; Dos version 3.1
  135.         db    000h,003h,038h,027h       ; Dos version 3.0
  136.         db    000h,002h,028h,00Ah       ; Dos version 2.0
  137.         db    000h,000h,000h,000h       ; 000h's, to end the compare.
  138.  
  139. HandleToName    endp
  140.  
  141. Handle2Name     ends
  142.  
  143.         end
  144.